package com.example.lin.zyfypt_327ljd.model;

//import com.example.lin.zyfypt_327ljd.bean.LoginBean;
import com.example.lin.zyfypt_327ljd.iface.LogoutListener;
import com.example.lin.zyfypt_327ljd.iface.Logoutiface;
import com.example.lin.zyfypt_327ljd.service.LogoutService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lin on 2017/4/20.
 */

//model 获取文章数据
public class LogoutModel implements Logoutiface {
    private Retrofit retrofit;
    //public String session;
    private  String BASEURL
            ="http://amicool.neusoft.edu.cn/";
    //构造函数
    public LogoutModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getResultList(String SessionID, final LogoutListener logoutListener) {
        LogoutService logoutService=retrofit.create(LogoutService.class);
        Call<String> call = logoutService.logout(SessionID);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful() && response != null) {
//                    logoutListener.onResponse(response.body());
                }
                else logoutListener.onFail("on response fail");
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                logoutListener.onFail(t.toString());
            }
        });
    }
}
